﻿using System.Threading;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTB.Standard
{
    public partial class frmFlashScreen : XtraForm
    {
        public frmFlashScreen()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.DoubleBuffer |
                     ControlStyles.ResizeRedraw |
                     ControlStyles.UserPaint,
                     true);
            InitializeComponent();
            Update();
            pictureEdit1.Update();
            FadeIn(this, 0.05, false, 1);
        }

        public void EventAction(object sender)
        {
            if (InvokeRequired)
            {
                TimerCallback tb = EventAction;
                Invoke(tb, new[] {sender});
            }
            else
            {
                Opacity += 0.05;
            }
        }

        public void SetCaption(string message)
        {
            //if (!Visible) Visible = true;
            lblMessage.Text = message;
            lblMessage.Update();
            Update();
            pictureEdit1.Update();
        }

        public void SetProcess(string caption, int position)
        {
            //if (!Visible) Visible = true;

            lblMessage.Text = caption;
            progressBarControl1.Position = position;
            progressBarControl1.Update();
            lblMessage.Update();
            Update();
            pictureEdit1.Update();
        }

        public void FadeOut(Form fadeForm, double speed)
        {
            FadeOut(fadeForm, speed, false);
        }

        public void FadeOut()
        {
            FadeOut(this);
        }

        public void FadeOut(Form fadeForm)
        {
            FadeOut(fadeForm, 0.01);
        }

        //INSTANT C# NOTE: C# does not support optional parameters. Overloaded method(s) are created above.
        //ORIGINAL LINE: Public Sub FadeOut(ByVal FadeForm As Form, Optional ByVal speed As Double = 0.01,Optional ByVal disposeForm As Boolean = false)
        public void FadeOut(Form FadeForm, double speed, bool disposeForm)
        {
            double i = 0;
            for (i = 1; i >= 0; i -= speed)
            {
                FadeForm.Opacity = i;
            }
        }

        public void FadeIn(Form iForm, double speed, bool disposeForm)
        {
            FadeIn(iForm, speed, disposeForm, 10);
        }

        public void FadeIn(Form iForm, double speed)
        {
            FadeIn(iForm, speed, false);
        }

        public void FadeIn()
        {
            FadeIn(this);
        }

        public void FadeIn(Form iForm)
        {
            FadeIn(iForm, 0.01);
        }

        //INSTANT C# NOTE: C# does not support optional parameters. Overloaded method(s) are created above.
        //ORIGINAL LINE: Public Sub FadeIn(ByVal iForm As Form, Optional ByVal speed As Double = 0.01,Optional ByVal disposeForm As Boolean = false, Optional ByVal delay As Double = 0)
        public void FadeIn(Form iForm, double speed, bool disposeForm, int delay)
        {
            double i = 0;
            for (i = 0; i <= 1; i += speed)
            {
                Thread.Sleep(delay);
                iForm.Opacity = i;
            }
        }
    }
}